package com.ecp.commons.fulltext;

import java.util.Iterator;
import java.util.Map;

public class IndexerManager {

	private Map<String, Indexer>	objtype2indexerMap;

	public IndexerManager() {
	}

	public Indexer getIndexer(int objtype) throws Exception {
		Indexer indexer = (Indexer) objtype2indexerMap.get("" + objtype);

		if (indexer != null && indexer.isOpen() == false) {
			indexer.open();
		}
		return indexer;
	}

	public void init() {
		for (Iterator<Indexer> it = objtype2indexerMap.values().iterator(); it.hasNext();) {
			Indexer indexer = it.next();
			try {
				indexer.init();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}

	public void setObjtype2indexerMap(Map<String, Indexer> objtype2indexerMap) {
		this.objtype2indexerMap = objtype2indexerMap;
	}

	public Map<String, Indexer> getObjtype2indexerMap() {
		return objtype2indexerMap;
	}

	public void closeall() throws Exception {
		for (Iterator<Indexer> it = objtype2indexerMap.values().iterator(); it.hasNext();) {
			Indexer indexer = it.next();
			if (indexer.isOpen()) {
				indexer.close();
			}
		}
	}
}
